import QtQuick 2.2
import QtQuick.Window 2.1

Window {
    id:root
    visible: true
    width: 768
    height: 1024

    signal sendpresskey(int key)

    property bool jflag:false
    property bool bellen : false


    MouseArea {
        id: mouseAreamain
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        onClicked: {
            if (mouse.button == Qt.RightButton)
            {
                console.log("right click")
                Qt.quit();
            }
            else
            {
                console.log("clicked")
                timerbl.stop()
                timerbl.start()
                sendpresskey(23);//开背光
            }
        }
    }

    Loader { id: passworduiLoader;anchors.fill: parent; source: 'PasswordUi.qml'}
    Loader { id: selectfloorLoader; anchors.fill: parent;source: 'SelectfloorUi.qml' }
    Loader { id: repairLoader; anchors.fill: parent;source: 'RepairUi.qml' }

    Connections {
        target: passworduiLoader.item
        onStart: {
            selectfloorLoader.visible=true;
            selectfloorLoader.item.btreply("");
            repairLoader.visible=false;
            passworduiLoader.visible=false;
        }
        onKeypress: {
            selectfloorLoader.item.bellkey(key);
            repairLoader.item.bellkey(key);
            sendpresskey(key);
            timerbl.stop()
            timerbl.start()
            sendpresskey(23);//开背光

        }
    }

    Connections {
        target: selectfloorLoader.item
        onStart: {
            selectfloorLoader.visible=false;
            repairLoader.visible=true;
            passworduiLoader.visible=false;
        }

        onTout: {
            selectfloorLoader.visible=false;
            repairLoader.visible=false;
            passworduiLoader.visible=true;
        }

       onKeypress: {
           repairLoader.item.bellkey(key);
           passworduiLoader.item.bellkey(key);
           sendpresskey(key);
           timerbl.stop()
           timerbl.start()
           sendpresskey(23);//开背光
       }
    }

    Connections {
        target: repairLoader.item
        onStart: {
            selectfloorLoader.visible=true;
            selectfloorLoader.item.btreply("");
            repairLoader.visible=false;
            passworduiLoader.visible=false;
        }
        onKeypress: {
            selectfloorLoader.item.bellkey(key);
            passworduiLoader.item.bellkey(key);
            sendpresskey(key);
            timerbl.stop()
            timerbl.start()
            sendpresskey(23);//开背光
        }
    }

    function state_c(str)
    {
         selectfloorLoader.item.state_c(str);
    }

    function flr_c(num)
    {
         selectfloorLoader.item.flr_c(num);
    }

    function dir_c(num)
    {
        selectfloorLoader.item.dir_c(num);
    }

    function regflr_c(num)
    {
         selectfloorLoader.item. regflr_c(num);
    }

    function unregflr_c(num)
    {
         selectfloorLoader.item. unregflr_c(num);
    }

    function voice_c(num)
    {
         selectfloorLoader.item. voice_c(num);
    }

    function vision_c(num)
    {
         selectfloorLoader.item.vision_c(num);
    }

    function light_c(num)
    {
         repairLoader.item.light_c(num);
    }

    function fan_c(num)
    {
         repairLoader.item.fan_c(num);
    }

    function jl_c(num)
    {
         //repairLoader.item.jl_c(num);

            if(bellen)
                return
    //        if(num===root.jflag)
    //            return
            jflag = num

            if(jflag)
            {
            selectfloorLoader.item.bellkey(15);
            passworduiLoader.item.bellkey(15);
            repairLoader.item.bellkey(15);
            }
            else
            {
            selectfloorLoader.item.bellkey(16);
            passworduiLoader.item.bellkey(16);
            repairLoader.item.bellkey(16);
            }


    }

    Timer {
       id: timerbl;
       interval: 180000;
       running: false
       repeat: false;
       triggeredOnStart: false;
       onTriggered:{
            sendpresskey(22);//关背光
       }
   }

     Component.onCompleted: {
         selectfloorLoader.visible=false;
         repairLoader.visible=false;
         passworduiLoader.visible=true;
         timerbl.start()
         sendpresskey(23);//开背光
     }

}
